<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>删除事件</title>
  <style>
    div {
      width: 100px;
      height: 100px;
      background-color: pink;
    }
  </style>
</head>
<body>
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <script>
    var divs = document.querySelectorAll('div')
    divs[0].onclick = function () {
      alert(11)
      // 1. 传统方式删除事件
      divs[0].onclick = null
    }
    // 2. removeEventListener 删除事件
    divs[1].addEventListener('click', fn)  // 里面的fn 不需要调用加小括号

    function fn () {
      alert(22)
      divs[1].removeEventListener('click', fn)
    }

    // 3. detachEvent        IE6.7.8
    // divs[2].attachEvent('onclick', fn1)
    //
    // function fn1 () {
    //   alert(33)
    //   divs[2].detachEvent('onclick', fn1)
    // }
  </script>
</body>
</html>